# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=reaper
pkgver=6.79
pkgrel=2
pkgdesc="A complete digital audio production application for computers"
arch=(loong64 x86_64)
url="https://reaper.fm"
license=(custom)
groups=(pro-audio)
depends=(
  alsa-lib libasound.so
  fontconfig
  gcc-libs
  glibc
  hicolor-icon-theme
  libglvnd
  libx11
  libxi
)
makedepends=(
  kservice
  xdg-utils
)
optdepends=(
  'jack: for JACK support'
  'pulseaudio: for PulseAudio support'
  'python: for Python plugins'
  'reapack: for managing reaper plugins'
  'sws: for the SWS/S&M plugin extension'
)
provides=(
  clap-host
  lv2-host
  vst-host
  vst3-host
)
options=(!debug)
source=(
  https://reaper.fm/files/${pkgver::1}.x/reaper${pkgver//.}_linux_$CARCH.tar.xz
  redistribution.eml
)
sha512sums=('4ef211895e3f7fed2424d76e5604242531bea3a490db3cef869f38765bc15f50f8419ceaa8b6ced5e521564352a82781e6cc1d75ff59b86cc83cb3264287cfd5'
            'a2746fa0b847dbd587f24983569b01120f4706306242223c8857360219569d965df8c25c98f31d68140eb66d7458384653b5b042f7433a84957a990d8e587d92')
b2sums=('4447c2d4fa21865d5ed0773a644564e03cc0280941c250b76e7485e74ae8e5727c41e1fb324e3601ef718e3619ab2d865fc350503a2edf79853f37d0816b8a82'
        'ddbf47cb04ad9e9fb937b09a0ea0c88d4416ceaabc4e420750ff9303447a50a323060f018bd9f52907a1a5e4ea3ebe685eb336d1b6f4bbbc89a12e2370be8728')

package() {
  cd ${pkgname}_linux_$CARCH
  XDG_DATA_HOME="$srcdir/xdg/" ./install-reaper.sh --install "$pkgdir/usr/lib" --integrate-user-desktop
  # remove unneeded uninstallation script
  rm -v "$pkgdir/usr/lib/${pkgname^^}/uninstall-reaper.sh"

  # strip $pkgdir from XDG desktop Exec line
  sed -e "s|$pkgdir||g" -i "$srcdir/xdg/applications/"*.desktop
  # install only required files for XDG integration
  install -vDm 644 "$srcdir/xdg/applications/"*.desktop -t "$pkgdir/usr/share/applications/"
  install -vDm 644 "$srcdir/xdg/mime/packages/"*.xml -t "$pkgdir/usr/share/mime/packages/"
  install -vDm 644 "$srcdir/xdg/icons/hicolor/256x256/apps/"*.png -t "$pkgdir/usr/share/icons/hicolor/256x256/apps/"

  # add convenience symlink to PATH
  install -vdm 755 "$pkgdir/usr/bin"
  ln -sv /usr/lib/${pkgname^^}/$pkgname "$pkgdir/usr/bin/$pkgname"

  # install EULA and redistribution allowance
  install -vDm 644 "$pkgdir/usr/lib/${pkgname^^}/EULA.txt" -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 "$srcdir/redistribution.eml" -t "$pkgdir/usr/share/licenses/$pkgname/"
}
